package com.module.framework.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.module.framework.domain.Expire;
import com.module.framework.domain.LoginUser;
import com.module.framework.dto.ExpireDTO;
import com.module.framework.mapper.ExpireMapper;
import com.module.framework.service.ExpireService;
import com.module.framework.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExpireServiceImpl extends ServiceImpl<ExpireMapper, Expire> implements ExpireService {

    @Autowired
    private ExpireMapper expireMapper;

    @Override
    public PageVO expireList(ExpireDTO expireDTO) {
        Integer pageNum = expireDTO.getPageNum();
        String name = expireDTO.getName();
        Integer cateId = expireDTO.getCateId();
        PageVO pageVO = null;

        // 根据id 查询信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Long userId = loginUser.getUser().getId();
        List<Expire> lists = expireMapper.selectByIdList(userId);
        pageVO = new PageVO(lists, lists.size());

        return pageVO;
    }

    @Override
    public Expire getExpireInfo(Integer id) {
        Expire hisLend = expireMapper.selectByIdVO(id);
        return hisLend;
    }
}
